package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.TbGoods;
import com.qf.mapper.TbGoodsMapper;
import com.qf.service.TbGoodsService;
import com.qf.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import java.util.List;

@Service
public class TbGoodsServiceImpl implements TbGoodsService {

    @Autowired
    private TbGoodsMapper mapper;
    @Override
    public PageResult<TbGoods> selectPage(String catId, String branId, Integer page, Integer size) {
        PageHelper.startPage(page,size);
        List<TbGoods> pAge = mapper.findPage(catId, branId);
        PageInfo pageInfo = new PageInfo(pAge);
        PageResult<TbGoods> pageResult = new PageResult<>();
        pageResult.setTotal((int) pageInfo.getTotal());
        pageResult.setData(pageInfo.getList());
        pageResult.setPages(pageInfo.getPages());

        return pageResult;
    }

    @Override
    public TbGoods findById(String goodsId) {
        return mapper.findById(goodsId);
    }
}
